{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import torch\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([[[[46.,  8., 19., 28.],\n          [ 0., 23., 13., 17.],\n          [ 4.,  5., 14., 34.],\n          [16., 27., 12., 30.]]],\n\n\n        [[[45., 39., 43.,  1.],\n          [11., 22., 26., 20.],\n          [10., 15.,  6., 36.],\n          [ 7., 35., 29., 38.]]],\n\n\n        [[[ 9., 42., 31., 37.],\n          [ 2., 18.,  3., 41.],\n          [33., 44., 40., 21.],\n          [24., 32., 47., 25.]]]])"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = torch.arange(48)\n",
    "idx = torch.randperm(arr.size(0))\n",
    "\n",
    "# 根据随机排列的索引重新排列数组\n",
    "arr = arr[idx]\n",
    "arr = arr.reshape(3, 1, 4, 4).to(torch.float32)\n",
    "arr"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor(23.5000)"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.mean()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor(23.5000)"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr.mean(dim=(-2, -1)).mean()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "pytorch",
   "language": "python",
   "display_name": "pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}